#include <Comm.h>


static u16 test_arr_u16[] = {1, 2, 3, 255, 256, 257};  // machine is little-endian
static void test_bsToU16() {
    Serial.println("test_bsToU16");
    byte *buf = (uint8_t *) test_arr_u16;
  
  for (int i=0; i<sizeof(test_arr_u16)/sizeof(uint16_t); i++) {
    Serial.print(i); Serial.print("> ");
    Serial.print(test_arr_u16[i]); Serial.print(" is ");
    Serial.print(bsToU16(buf, i*2)); Serial.println(" ?");
  }
}

static void test_bsToU16D1() {
  Serial.println("test_bsToU16D1");
  byte *buf = (uint8_t *) test_arr_u16;
  
  for (int i=0; i<sizeof(test_arr_u16)/sizeof(uint16_t); i++) {
    Serial.print(i); Serial.print("> ");
    Serial.print(test_arr_u16[i]); Serial.print(" /10 is ");
    Serial.print(bsToU16D1(buf, i*2)); Serial.println(" ?");
  }
}

static void test_U16ToBs() {
  Serial.println("test_U16ToBs");
  byte *buf = (uint8_t *) test_arr_u16;
  for (int i=0; i<sizeof(test_arr_u16)/sizeof(uint16_t); i++) {
    uint16_t val = 253 + i;
    U16ToBs(&(buf[2*i]), val);
    Serial.print(test_arr_u16[i]); Serial.print(" is ");
    Serial.print(val); Serial.println(" ?");
  }
}

static void test_U16D1ToBs() {
  Serial.println("test_U16D1ToBs");
  byte *buf = (uint8_t *) test_arr_u16;
  for (int i=0; i<sizeof(test_arr_u16)/sizeof(uint16_t); i++) {
    float val = 253.0 + i;
    U16D1ToBs(&(buf[2*i]), val);
    Serial.print(test_arr_u16[i]); Serial.print(" is ");
    Serial.print(val); Serial.println(" *10?");
  }
}


static int16_t test_arr_s16[] = {-255,-256,-2,-1, 1,2,255,256};
static void test_bsToS16() {
  Serial.println("test_bsToS16");
  uint8_t *buf = (uint8_t *)test_arr_s16;
  for (int i=0; i<sizeof(test_arr_s16)/sizeof(int16_t); i++) {
    Serial.print(test_arr_s16[i]); Serial.print(" is ");
    Serial.print(bsToS16(buf, 2*i)); Serial.println(" ?");
  }
}

void test_bsToS16D1() {
  Serial.println("test_bsToS16D1");
  uint8_t *buf = (uint8_t *)test_arr_s16;
  for (int i=0; i<sizeof(test_arr_s16)/sizeof(int16_t); i++) {
    Serial.print(test_arr_s16[i]); Serial.print(" is ");
    Serial.print(bsToS16D1(buf, 2*i)); Serial.println(" *10 ?");
  }
}

static void test_S16ToBs() {
  Serial.println("test_S16ToBs");
  uint8_t *buf = (uint8_t *)test_arr_s16;
  for (int i=0; i<sizeof(test_arr_s16)/sizeof(int16_t); i++) {
    int16_t val = -2 + i;
    S16ToBs(&(buf[2*i]), val);
    Serial.print(test_arr_s16[i]); Serial.print(" is ");
    Serial.print(val); Serial.println(" ?");
  }
}

static void test_S16D1ToBs() {
  Serial.println("test_S16D1ToBs");
  uint8_t *buf = (uint8_t *)test_arr_s16;
  for (int i=0; i<sizeof(test_arr_s16)/sizeof(int16_t); i++) {
    float val = -2 + i;
    S16D1ToBs(&(buf[2*i]), val);
    Serial.print(test_arr_s16[i]); Serial.print(" is ");
    Serial.print(val); Serial.println(" *10 ?");
  }
}
